package com.geezdata.cps.base.response;

import java.io.Serializable;

import com.geezdata.cps.base.enums.ErrorCode;

public class BaseResponse<T> implements Serializable {
	private static final long serialVersionUID = 1L;
	
    protected boolean success;
    protected Integer code;
    protected String msg;
    protected T result;

    public BaseResponse() {
    }
    
    public static final <T> BaseResponse<T> success(T t) {
    	BaseResponse<T> r = new BaseResponse<T>();
        r.success = true;
        r.code = ErrorCode.SUCCESS.getCode();
        r.msg = ErrorCode.SUCCESS.getDesc();
        r.result = t;
        return r;
    }

    public static final <T> BaseResponse<T> error(Integer code, String msg) {
    	BaseResponse<T> r = new BaseResponse<T>();
        r.success = false;
        r.code = code;
        r.msg = msg;
        return r;
    }

    public boolean isSuccess() {
        return success;
    }

    public Integer getCode() {
        return code;
    }
    
    public String getMsg() {
        return msg;
    }

    public T getResult() {
        return result;
    }
}
